<%@ page import="java.util.ArrayList" %>
<%@ page import="cn.maka.domain.User" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>jstl_UserTest</title>
</head>
<body>
<%
    ArrayList<User> users = new ArrayList<>();
    users.add(new User(1,"maka","123"));
    users.add(new User(2,"zhang","456"));
    users.add(new User(3,"liu","123"));
    users.add(new User(4,"lizi","123"));

    request.setAttribute("userList",users);

%>

<table border="1" width="400" align="center">
    <tr>
        <th>编号</th>
        <th>姓名</th>
        <th>密码</th>
    </tr>

    <c:forEach items="${userList}" var="user" varStatus="s" >
        <c:if test="${s.count % 2 != 0}" >
            <tr bgcolor="#7fffd4">
                <td>${s.count}</td>
                <td>${user.username}</td>
                <td>${user.password}</td>
            </tr>
        </c:if>

        <c:if test="${s.count % 2 == 0}">
            <tr bgcolor="#8fbc8f">
                <td>${s.count}</td>
                <td>${user.username}</td>
                <td>${user.password}</td>
            </tr>
        </c:if>
    </c:forEach>

</table>

</body>
</html>
